package com.spring.cloud.redissentinel;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@RestController
public class RedisSentinelApplication {

    public static void main(String[] args) {
        SpringApplication.run(RedisSentinelApplication.class, args);
    }

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/write")
    public Map<String,String> testWrite(){
        Map<String,String> result = new HashMap<>();
        result.put("key1","value1");
        stringRedisTemplate.opsForValue().multiSet(result);
        return result;
    }

    @GetMapping("/read")
    public Map<String,String> testRead(){
        Map<String,String> result = new HashMap<>();
        result.put("key1",stringRedisTemplate.opsForValue().get("key1"));

        return result;
    }
}
